//
//  TheTypeView.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/27.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "TheTypeView.h"
#import "JTCSM.h"

@interface TheTypeView (){
    
    NSArray *dataArray;
}

@end

@implementation TheTypeView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat space = 20;
        CGFloat top = 15;
        CGFloat labelHeight = 40;
        self.frame = [UIScreen mainScreen].bounds;
        self.backgroundColor = RGBACOLOR(89, 89, 89, 0.8);
        self.userInteractionEnabled = YES;
        UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width-2*space, labelHeight*7+top*2)];
        backview.center = self.center;
        backview.backgroundColor = [UIColor whiteColor];
        backview.userInteractionEnabled = YES;
        [self addSubview:backview];
        [df layerWithView:backview radius:6 width:0 color:nil];
        CGFloat width = backview.frame.size.width;
        
        dataArray = @[@"选择查看类型",@"全部",@"纯消费",@"线上还款",@"线下还款",@"充值",@"提现"];
        for (int i = 0; i<dataArray.count; i++) {
            UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(space, top+labelHeight*i, width-2*space, labelHeight) text:dataArray[i] font:16 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
            titleLabel.tag = 1000+i;
            titleLabel.userInteractionEnabled = YES;
            [backview addSubview:titleLabel];
            if (i == 0) {
                titleLabel.textColor = RGBACOLOR(193, 193, 193, 1);
                titleLabel.textAlignment = NSTextAlignmentCenter;
            }else{
                [df addTapGestureRecognizerWithTarget:self action:@selector(getzheLeixing:) andaddView:titleLabel];
            }
            [df lineViewWithHeightofTop:KVIEW_Y(titleLabel) superView:backview spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
            
            
        }
       
        
    }
    
    return self;
}

- (void)getzheLeixing:(UITapGestureRecognizer *)tap{
    NSInteger index = [tap view].tag-1000;
    
    [self.delegate getTheTitle:dataArray[index] type:[NSString stringWithFormat:@"%ld",index-1]];
    [self removeview];
}

- (void)removeview{
    [self removeFromSuperview];
}

@end
